<template>
  <div class="view-wrapper">
    <div class="head">
      <el-form :inline="true" :model="formInline" class="demo-form-inline">
        <el-form-item label="">
          <el-input placeholder="活动名称/优惠券名称/手机号/核销地点" style="width: 280px" v-model="formInline.query"
            class="input-with-select">
          </el-input>
        </el-form-item>
        <el-form-item label="优惠券类型：">
          <el-select v-model="formInline.couponType" placeholder="请选择">
            <el-option v-for="item in openLs" :key="item.id" :label="item.value" :value="item.id">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="使用时间：">
          <el-date-picker v-model="date" type="daterange" value-format="yyyy-MM-dd" range-separator="至"
            start-placeholder="开始日期" end-placeholder="结束日期">
          </el-date-picker>
        </el-form-item>
        <el-form-item>
          <el-button @click="reset">重置</el-button>
          <el-button type="primary" @click="onSubmit">查询</el-button>
        </el-form-item>
      </el-form>
    </div>
    <div class="listBox">
      <div class="listBox_head">
        <div></div>
        <export-excel-button title="用券明细" action="/customer/platform/coupon/useList/export" :params="ExportParams" />
      </div>
      <ex-table ref="table" :loading="loading" :table-column="tableColumn" :table-data="tableData"
        @pageSizeChange="handleSizeChange" @currentPageChange="handleCurrentChange">
        <!-- <template v-slot:operate="{ scope }">
          <el-button @click="edit(scope.row.shopId)" size="small">编辑</el-button>
          <el-button type="primary" size="small">复制链接</el-button>
        </template> -->
      </ex-table>
    </div>
  </div>
</template>
<script>
  // components
  import {
    useCouponLs,
    adminDict
  } from "@/api/couponManagement";
  import handlePageMixin from "@/mixins/handlePageMixin";
  import ExportExcelButton from "@/components/ExportExcelButton/index";
  export default {
    //   name: "",
    components: {
      ExportExcelButton,
    },
    mixins: [handlePageMixin],
    data() {
      return {
        loading: false,
        formInline: {
          query: "", //活动名称/优惠券名称/手机号
          couponType: "", //优惠券类型;(1 满减券 2 折扣券 3 礼品券) platform_coupon_type
        },
        openLs: [],
        date: [],
        tableData: [],
        tableColumn: [{
            prop: "couponCode",
            label: "券码"
          },
          {
            prop: "platformName",
            label: "领券渠道",
            width: 150
          },
          {
            prop: "activityName",
            label: "活动名称"
          },
          {
            prop: "couponName",
            label: "优惠券名称",
            width: 130
          },
          {
            prop: "couponTypeDict",
            label: "优惠券类型",
            width: 130
          },
          {
            prop: "nickName",
            label: "领券人",
            width: 140
          },
          {
            prop: "phoneNumber",
            label: "手机号",
            width: 130
          },
          {
            prop: "shopName",
            label: "核销地点",
             width: 160
          },
          {
            prop: "orderMoney",
            label: "消费金额"
          },
          {
            prop: "discountsMoney",
            label: "优惠金额",
            width: 130
          },
          {
            prop: "payMoney",
            label: "现金支付",
            width: 130
          },
        //   {
        //     prop: "regionName",
        //     label: "余额支付",
        //     width: 130
        //   },
          {
            prop: "useTime",
            label: "使用时间",
            width: 140
          },
        ],
      };
    },
    created() {
        this.getTypeList();
      this.getList();
    },
    computed: {
      ExportParams() {
        const params = {
          ...this.pageOptions,
          ...this.formInline,
          startTime: this.date[0],
          endTime: this.date[1],
        };
        return params;
      },
    },
    methods: {
      getTypeList() {
        //获取字典
        const params = {
          dictType: "platform_coupon_type",
        };
        adminDict(params).then((res) => {
          this.openLs = res.result[0].dictList;
        });
      },
      onSubmit() {
        //查询
        console.log(this.formInline);
        this.pageOptions.pageNum = 1;
        this.$refs.table.pageOptions.pageNum = 1;
        this.getList();
      },
      reset() {
        this.formInline = {};
        this.date = [];
        this.pageOptions.pageNum = 1;
        this.$refs.table.pageOptions.pageNum = 1;
        this.getList();
      },
      getList() {
        const params = {
          ...this.pageOptions,
          ...this.formInline,
          startTime: this.date[0],
          endTime: this.date[1],
        };
        this.loading = true;
        useCouponLs(params)
          .then((res) => {
            const {
              total,
              records
            } = res.result;
            // records.forEach((item) => {
              
            // });
            this.$refs.table.pageOptions.total = total;
            this.tableData = records;
          })
          .finally(() => {
            this.loading = false;
          });
      },
      lookDetail(id) {
        this.$router.push({
          path: "/clientManagement/shopDetail",
          query: {
            id: id
          },
        });
      },
    },
  };

</script>
<style lang="scss">
  .el-card-title {
    font-size: 20px;
  }

</style>
<style lang="scss" scoped>
  .head {
    box-shadow: 0px 4px 12px 0px rgb(1 41 99 / 6%);
    background-color: #fff;
    border-radius: 8px;
    //   height: 120px;
    padding: 20px 20px 0;
  }

  .el-form--inline .el-form-item {
    margin-right: 30px;
  }

  .listBox {
    box-shadow: 0px 4px 12px 0px rgb(1 41 99 / 6%);
    background-color: #fff;
    border-radius: 8px;
    //   height: 120px;
    padding: 20px 20px;
    margin-top: 10px;
  }

  .table_list {
    display: flex;
    align-items: center;
    // border: 1px solid #DCDFE6;
    border-radius: 7px;
    width: 220px;
    margin-bottom: 10px;
  }

  .tableBox {
    width: calc(100% / 3);
    height: 36px;
    text-align: center;
    line-height: 36px;
    color: #303133;
    font-size: 14px;
    border: 1px solid #dcdfe6;
    border-right: 0;
  }

  .tableBox:first-child {
    border-radius: 7px 0px 0px 7px;
  }

  .tableBox:last-child {
    border-right: 1px solid #dcdfe6;
    border-radius: 0px 7px 7px 0px;
  }

  .spchoosetext {
    background-color: #fff4e6;
    color: #ff9300;
    // border: 1px solid #ff9300;
  }

  .listBox_head {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 20px;
  }

  .el-select .el-input {
    width: 130px;
  }

  .input-with-select .el-input-group__prepend {
    background-color: #fff;
  }

  .head ::v-deep.el-input-group__prepend {
    width: 110px !important;
  }

</style>
